<html>
<head><meta charset="utf-8"><title>Handling clobbers · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html">Handling clobbers</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233433837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233433837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233433837">(Apr 07 2021 at 05:32)</a>:</h4>
<p>However clobber("all") is tricker: we can't actually clobber all registers because LLVM reserved registers must not be clobbered. If the user specifies <code>clobber("all")</code> then they may be under the impression that they are allowed to clobber those registers.</p>



<a name="233433939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233433939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233433939">(Apr 07 2021 at 05:33)</a>:</h4>
<p>I liked the <code>clobber(...)</code> proposal, plus some aliases like "call" or perhaps "C".</p>



<a name="233433940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233433940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233433940">(Apr 07 2021 at 05:33)</a>:</h4>
<p>Do you mean things like the stack pointer? I think most people understand that they cannot leave that different than they received it without breaking things.</p>



<a name="233433975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233433975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233433975">(Apr 07 2021 at 05:34)</a>:</h4>
<p>I was thinking of the frame pointer and base pointer <code>ebp</code> and <code>ebx</code>.</p>



<a name="233434028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434028">(Apr 07 2021 at 05:34)</a>:</h4>
<p>Wait, what? You can't clobber <em>ebx</em>?</p>



<a name="233434045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434045">(Apr 07 2021 at 05:34)</a>:</h4>
<p>Why would that be reserved?</p>



<a name="233434200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434200">(Apr 07 2021 at 05:36)</a>:</h4>
<p>Also, for labels, we can always make syntax better/simpler in the future, but the only things that need to happen before stabilization are changes that make things <em>stop</em> working. And I still remain skeptical that we want to prevent people from using labels directly in asm.</p>



<a name="233434201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434201">(Apr 07 2021 at 05:36)</a>:</h4>
<p>It is reserved if you have stack alignment and variable-sized locals.</p>



<a name="233434230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434230">(Apr 07 2021 at 05:37)</a>:</h4>
<p><a href="https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/X86/X86RegisterInfo.cpp#L636">https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/X86/X86RegisterInfo.cpp#L636</a></p>



<a name="233434245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434245">(Apr 07 2021 at 05:37)</a>:</h4>
<p>That seems like an unfortunate limitation in LLVM. It doesn't seem like there's a fundamental reason it couldn't use a different register.</p>



<a name="233434412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434412">(Apr 07 2021 at 05:40)</a>:</h4>
<p>In that case, it seems like we should skip adding "all" while that limitation exists. At least if people write ebx explicitly we can give them an explanatory error message.</p>



<a name="233434462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434462">(Apr 07 2021 at 05:40)</a>:</h4>
<p>At the moment ebx is still allowed as a register, I'm considering switching it to be disallowed.</p>



<a name="233434463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434463">(Apr 07 2021 at 05:40)</a>:</h4>
<p>Because I agree, if people use "all" they will expect "all", and I think they'd be as shocked as I was if that doesn't include ebx.</p>



<a name="233434489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434489">(Apr 07 2021 at 05:41)</a>:</h4>
<p>Could it be disallowed <em>only</em> when it's actually an issue (because alloca)?</p>



<a name="233434502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434502">(Apr 07 2021 at 05:41)</a>:</h4>
<p>The thing is, LLVM will only reserve ebx in very rare cases (stack realignment &amp; DST local)</p>



<a name="233434555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434555">(Apr 07 2021 at 05:42)</a>:</h4>
<p>No, because we don't have enough information in the frontend to determine this.</p>



<a name="233434569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434569">(Apr 07 2021 at 05:42)</a>:</h4>
<p>It's only knowable in the backend after all the inlining has been done.</p>



<a name="233434572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434572">(Apr 07 2021 at 05:42)</a>:</h4>
<p>Could we manually generate code to save and restore ebx if someone specifies a clobber of it?</p>



<a name="233434703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434703">(Apr 07 2021 at 05:44)</a>:</h4>
<p>Not easily. How would you pass the value in/out?</p>



<a name="233434729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434729">(Apr 07 2021 at 05:44)</a>:</h4>
<p>Via an extra register? x86-32 is already <em>very</em> register-pressured, it may not be possible to find another register.</p>



<a name="233434764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434764">(Apr 07 2021 at 05:45)</a>:</h4>
<p>push/pop? Assembly can assume the stack is valid.</p>



<a name="233434796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434796">(Apr 07 2021 at 05:45)</a>:</h4>
<p>That doesn't help, where you do get the value to push in at the start? It still needs to come from the asm.</p>



<a name="233434868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434868">(Apr 07 2021 at 05:46)</a>:</h4>
<p>Hmm, perhaps we can cheat here and use LLVM memory constraints.</p>



<a name="233434883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434883">(Apr 07 2021 at 05:46)</a>:</h4>
<p>I think I'm missing something. Are you talking about a clobber or an input? Also, good point.</p>



<a name="233434950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233434950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233434950">(Apr 07 2021 at 05:47)</a>:</h4>
<p>Let's see, consider <code>asm!("foo", inout("ebx") bar)</code>.</p>



<a name="233435060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435060">(Apr 07 2021 at 05:48)</a>:</h4>
<p>Yeah, memory or reg/mem constraint seems like the right answer there.</p>



<a name="233435077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435077">(Apr 07 2021 at 05:49)</a>:</h4>
<p>We could do this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="fm">asm!</span><span class="p">(</span><span class="w"></span>
<span class="w">    </span><span class="s">"mov {tmp}, ebx"</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="s">"mov ebx, {bar}"</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="s">"foo"</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="s">"mov {bar}, ebx"</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="s">"mov ebx, {tmp}"</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">tmp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mem</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="mi">0</span><span class="k">usize</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">bar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mem</span><span class="w"> </span><span class="n">bar</span><span class="p">,</span><span class="w"></span>
<span class="p">)</span><span class="w"></span>
</code></pre></div>



<a name="233435103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435103">(Apr 07 2021 at 05:49)</a>:</h4>
<p>That will be slow but it should work.</p>



<a name="233435155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435155">(Apr 07 2021 at 05:50)</a>:</h4>
<p>That works. Or push/pop ebx rather than using a declared temporary.</p>



<a name="233435180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435180">(Apr 07 2021 at 05:50)</a>:</h4>
<p>That doesn't work because we guarantee stack alignment in <code>asm!</code> unless the <code>nostack</code> option is set.</p>



<a name="233435199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435199">(Apr 07 2021 at 05:50)</a>:</h4>
<p>We can keep it aligned.</p>



<a name="233435205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435205">(Apr 07 2021 at 05:51)</a>:</h4>
<p><code>tmp</code> is already a stack location, just use that.</p>



<a name="233435230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435230">(Apr 07 2021 at 05:51)</a>:</h4>
<p>Sure, that works.</p>



<a name="233435293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435293">(Apr 07 2021 at 05:52)</a>:</h4>
<p>And all of this is in lieu of LLVM understanding enough to do it itself only when it wants ebx.</p>



<a name="233435311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435311">(Apr 07 2021 at 05:52)</a>:</h4>
<p>We could do the same for ebp too, right?</p>



<a name="233435325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435325">(Apr 07 2021 at 05:52)</a>:</h4>
<p>Yes. And the same for the frame/base pointer on other targets.</p>



<a name="233435341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435341">(Apr 07 2021 at 05:53)</a>:</h4>
<p>The downside is that this may be a silent performance gotcha in some cases.</p>



<a name="233435352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435352">(Apr 07 2021 at 05:53)</a>:</h4>
<p>But we don't really make any guarantees about performance anyways.</p>



<a name="233435365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435365">(Apr 07 2021 at 05:53)</a>:</h4>
<p>I like this plan. We don't promise efficiency for reserved registers, but we avoid breaking people who have a specific need for those registers. And we tell people who want performance to take it up with LLVM.</p>



<a name="233435414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435414">(Apr 07 2021 at 05:54)</a>:</h4>
<p>Also, we can document it so that it's less silent.</p>



<a name="233435510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435510">(Apr 07 2021 at 05:55)</a>:</h4>
<p>I assume your example above was pseudocode, and we'll internally generate a new anonymous parameter?</p>



<a name="233435522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435522">(Apr 07 2021 at 05:55)</a>:</h4>
<p>(or two, rather)</p>



<a name="233435530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435530">(Apr 07 2021 at 05:55)</a>:</h4>
<p>This will be handled in <code>rustc_codegen_llvm</code> in the last stages of asm codegen.</p>



<a name="233435597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435597">(Apr 07 2021 at 05:56)</a>:</h4>
<p>/me reviews the list of all reserved registers...</p>



<a name="233435610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435610">(Apr 07 2021 at 05:56)</a>:</h4>
<p>With this done, is there any other reason not to add both clobber(C) and clobber(all)?</p>



<a name="233435626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435626">(Apr 07 2021 at 05:57)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html">https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html</a></p>



<a name="233435632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435632">(Apr 07 2021 at 05:57)</a>:</h4>
<p>(Search for "Some registers cannot be used for input or output operands:")</p>



<a name="233435740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435740">(Apr 07 2021 at 05:59)</a>:</h4>
<p>Actually I think that my approach with <code>mem</code> won't work: In <code>mov {bar}, ebx</code>, LLVM may expand <code>{bar}</code> to an <code>ebx</code>-relative address.</p>



<a name="233435757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435757">(Apr 07 2021 at 05:59)</a>:</h4>
<p>It will definitely do that with <code>ebp</code></p>



<a name="233435990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233435990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233435990">(Apr 07 2021 at 06:02)</a>:</h4>
<p>(Now I remember why I didn't just implement that...)</p>



<a name="233436031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436031">(Apr 07 2021 at 06:02)</a>:</h4>
<p>I don't actually see ebx there.</p>



<a name="233436046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436046">(Apr 07 2021 at 06:02)</a>:</h4>
<p>I don't actually see ebx there.</p>



<a name="233436134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436134">(Apr 07 2021 at 06:03)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="fm">asm!</span><span class="p">(</span><span class="w"></span>
<span class="w">    </span><span class="s">"mov {tmp}, ebp"</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="s">"mov ebp, {bar}"</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="s">"foo"</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="s">"mov {bar}, ebp"</span><span class="p">,</span><span class="w"> </span><span class="c1">// &lt;-- {bar} is expanded to [ebp + 0x10]</span>
<span class="w">    </span><span class="s">"mov ebp, {tmp}"</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">tmp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mem</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="mi">0</span><span class="k">usize</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">bar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mem</span><span class="w"> </span><span class="n">bar</span><span class="p">,</span><span class="w"></span>
<span class="p">)</span><span class="w"></span>
</code></pre></div>



<a name="233436172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436172">(Apr 07 2021 at 06:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/216763-project-inline-asm/topic/Handling.20clobbers/near/233435311">said</a>:</p>
<blockquote>
<p>We could do the same for ebp too, right?</p>
</blockquote>
<p>no, you can't use memory operands to stack locations if you change ebp, since ebp could be used as the base register for those memory operands:</p>
<div class="codehilite" data-code-language="GAS"><pre><span></span><code><span class="nf">mov</span> <span class="nv">%rbp</span><span class="p">,</span> <span class="mi">12</span><span class="p">(</span><span class="nv">%rbp</span><span class="p">)</span> <span class="c1">// save</span>
<span class="nf">mov</span> <span class="nv">%ebp</span><span class="p">,</span> <span class="no">$42</span> <span class="c1">// clobber</span>
<span class="nf">mov</span> <span class="mi">12</span><span class="p">(</span><span class="nv">%rbp</span><span class="p">),</span> <span class="nv">%rbp</span> <span class="c1">// restore</span>
</code></pre></div>



<a name="233436238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436238">(Apr 07 2021 at 06:04)</a>:</h4>
<p>oh, well you already said what I wanted to while I was typing :)</p>



<a name="233436261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436261">(Apr 07 2021 at 06:04)</a>:</h4>
<p>Sigh. It's unfortunate we can't just require no-frame-pointer.</p>



<a name="233436324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436324">(Apr 07 2021 at 06:05)</a>:</h4>
<p>That doesn't help, LLVM will still use a frame pointer if it needs to, for example to handle stack realignment (over-aligned locals) or variable-length alloca.</p>



<a name="233436334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436334">(Apr 07 2021 at 06:05)</a>:</h4>
<p>also, <code>xlatb</code> <em>only</em> works with <code>%rbx</code>, so if you really want it, you need <code>%rbx</code></p>



<a name="233436396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436396">(Apr 07 2021 at 06:06)</a>:</h4>
<p>X86 frame layout: <a href="https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/X86/X86FrameLowering.cpp#L2253">https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/X86/X86FrameLowering.cpp#L2253</a></p>



<a name="233436426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436426">(Apr 07 2021 at 06:07)</a>:</h4>
<p>So, clobbers we can definitely support, because we can just push and pop (and maintain alignment of we need to). Inputs and outputs are the hard part.</p>



<a name="233436499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436499">(Apr 07 2021 at 06:08)</a>:</h4>
<p>I suppose.</p>



<a name="233436502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436502">(Apr 07 2021 at 06:08)</a>:</h4>
<p>Memory operands should be safe as long as we save and restore the register before we change its value.</p>



<a name="233436556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436556">(Apr 07 2021 at 06:08)</a>:</h4>
<p>Though keep in mind that if we do this, we are forfeiting any chance of supporting <code>mem</code> operands in the future since the stack offset will be wrong.</p>



<a name="233436599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436599">(Apr 07 2021 at 06:09)</a>:</h4>
<p>will LLVM always error if you clobber %ebx or %ebp and it can't allocate it? if so, we could just rely on propagating LLVM's error.</p>



<a name="233436607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436607">(Apr 07 2021 at 06:10)</a>:</h4>
<p>I think it just silently generates incorrect code.</p>



<a name="233436659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436659">(Apr 07 2021 at 06:10)</a>:</h4>
<p>Sadness...</p>



<a name="233436684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436684">(Apr 07 2021 at 06:10)</a>:</h4>
<p>For input only:</p>
<div class="codehilite"><pre><span></span><code>push ebp
// optionally align stack here
mov ebp, {val}
...
pop ebp
</code></pre></div>



<a name="233436727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436727">(Apr 07 2021 at 06:11)</a>:</h4>
<p>Except now you can't use <code>mem</code> for <code>{val}</code> since the <code>esp</code> offset will be off.</p>



<a name="233436790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436790">(Apr 07 2021 at 06:12)</a>:</h4>
<p>Ah, I was thinking of ebp-relative, not esp-relative.</p>



<a name="233436812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436812">(Apr 07 2021 at 06:12)</a>:</h4>
<p>Hrm...</p>



<a name="233436865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233436865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233436865">(Apr 07 2021 at 06:13)</a>:</h4>
<p>well...if we're going to get the out-of-line asm implementation anyway, why not rely on that for %ebp and/or %ebx clobbers?</p>



<a name="233437007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437007">(Apr 07 2021 at 06:15)</a>:</h4>
<p>or maybe for %ebx clobbers, just pass it through to LLVM and say we tried our best, IIRC clang doesn't do any better</p>



<a name="233437081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437081">(Apr 07 2021 at 06:16)</a>:</h4>
<p>It would be really nice if we could guarantee that a memory operand is not relative to a specific register.</p>



<a name="233437189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437189">(Apr 07 2021 at 06:19)</a>:</h4>
<p>hmm, how about allocating an array on stack, then passing the address of that array as a single register input operand, allowing us to guaranteed use only one reg to save/restore other regs</p>



<a name="233437216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437216">(Apr 07 2021 at 06:19)</a>:</h4>
<p>bypassing LLVM's memory operands completely</p>



<a name="233437491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437491">(Apr 07 2021 at 06:23)</a>:</h4>
<p>We could use a register input and just let LLVM error if we're out of registers. Doesn't work for all, works for calls or simple clobbers of ebp/end.</p>



<a name="233437534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437534">(Apr 07 2021 at 06:23)</a>:</h4>
<p>Consider Linux syscalls which take 6 arguments + the syscall number in registers. That's a fun one :P</p>



<a name="233437708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437708">(Apr 07 2021 at 06:25)</a>:</h4>
<p><span class="user-mention" data-user-id="229517">@Jacob Lifshay</span> 1) ow, 2) that could work.</p>



<a name="233437854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437854">(Apr 07 2021 at 06:27)</a>:</h4>
<div class="codehilite" data-code-language="C"><pre><span></span><code><span class="cm">/* Six-argument syscalls use an out-of-line helper, because an inline</span>
<span class="cm">   asm using all registers apart from %esp cannot work reliably and</span>
<span class="cm">   the assembler does not support describing an asm that saves and</span>
<span class="cm">   restores %ebp itself as a separate stack frame.  This structure</span>
<span class="cm">   stores the arguments not passed in registers; %edi is passed with a</span>
<span class="cm">   pointer to this structure.  */</span>
<span class="k">struct</span> <span class="nc">libc_do_syscall_args</span>
<span class="p">{</span>
  <span class="kt">int</span> <span class="n">ebx</span><span class="p">,</span> <span class="n">edi</span><span class="p">,</span> <span class="n">ebp</span><span class="p">;</span>
<span class="p">};</span>
</code></pre></div>



<a name="233437922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437922">(Apr 07 2021 at 06:28)</a>:</h4>
<p>Precedent.</p>



<a name="233437962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437962">(Apr 07 2021 at 06:29)</a>:</h4>
<p>That was glibc.</p>



<a name="233437968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437968">(Apr 07 2021 at 06:29)</a>:</h4>
<p>This is what musl does:</p>
<div class="codehilite" data-code-language="C"><pre><span></span><code><span class="k">static</span> <span class="kr">inline</span> <span class="kt">long</span> <span class="n">__syscall6</span><span class="p">(</span><span class="kt">long</span> <span class="n">n</span><span class="p">,</span> <span class="kt">long</span> <span class="n">a1</span><span class="p">,</span> <span class="kt">long</span> <span class="n">a2</span><span class="p">,</span> <span class="kt">long</span> <span class="n">a3</span><span class="p">,</span> <span class="kt">long</span> <span class="n">a4</span><span class="p">,</span> <span class="kt">long</span> <span class="n">a5</span><span class="p">,</span> <span class="kt">long</span> <span class="n">a6</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">__ret</span><span class="p">;</span>
<span class="cp">#if !defined(__PIC__) || !defined(BROKEN_EBX_ASM)</span>
    <span class="n">__asm__</span> <span class="n">__volatile__</span> <span class="p">(</span><span class="s">"pushl %7 ; push %%ebp ; mov 4(%%esp),%%ebp ; "</span> <span class="n">SYSCALL_INSNS</span> <span class="s">" ; pop %%ebp ; add $4,%%esp"</span>
        <span class="o">:</span> <span class="s">"=a"</span><span class="p">(</span><span class="n">__ret</span><span class="p">)</span> <span class="o">:</span> <span class="s">"a"</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="s">"b"</span><span class="p">(</span><span class="n">a1</span><span class="p">),</span> <span class="s">"c"</span><span class="p">(</span><span class="n">a2</span><span class="p">),</span> <span class="s">"d"</span><span class="p">(</span><span class="n">a3</span><span class="p">),</span> <span class="s">"S"</span><span class="p">(</span><span class="n">a4</span><span class="p">),</span> <span class="s">"D"</span><span class="p">(</span><span class="n">a5</span><span class="p">),</span> <span class="s">"g"</span><span class="p">(</span><span class="n">a6</span><span class="p">)</span> <span class="o">:</span> <span class="s">"memory"</span><span class="p">);</span>
<span class="cp">#else</span>
    <span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">a1a6</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> <span class="n">a1</span><span class="p">,</span> <span class="n">a6</span> <span class="p">};</span>
    <span class="n">__asm__</span> <span class="n">__volatile__</span> <span class="p">(</span><span class="s">"pushl %1 ; push %%ebx ; push %%ebp ; mov 8(%%esp),%%ebx ; mov 4(%%ebx),%%ebp ; mov (%%ebx),%%ebx ; "</span> <span class="n">SYSCALL_INSNS</span> <span class="s">" ; pop %%ebp ; pop %%ebx ; add $4,%%esp"</span>
        <span class="o">:</span> <span class="s">"=a"</span><span class="p">(</span><span class="n">__ret</span><span class="p">)</span> <span class="o">:</span> <span class="s">"g"</span><span class="p">(</span><span class="o">&amp;</span><span class="n">a1a6</span><span class="p">),</span> <span class="s">"a"</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="s">"c"</span><span class="p">(</span><span class="n">a2</span><span class="p">),</span> <span class="s">"d"</span><span class="p">(</span><span class="n">a3</span><span class="p">),</span> <span class="s">"S"</span><span class="p">(</span><span class="n">a4</span><span class="p">),</span> <span class="s">"D"</span><span class="p">(</span><span class="n">a5</span><span class="p">)</span> <span class="o">:</span> <span class="s">"memory"</span><span class="p">);</span>
<span class="cp">#endif</span>
    <span class="k">return</span> <span class="n">__ret</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>



<a name="233437969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233437969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233437969">(Apr 07 2021 at 06:29)</a>:</h4>
<p>Doing that automatically seems, I hesitate to say "reasonable", but, balanced in favor of correctness and user-friendliness.</p>



<a name="233438201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438201">(Apr 07 2021 at 06:32)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> The musl approach seems doable as well, yeah.</p>



<a name="233438255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438255">(Apr 07 2021 at 06:33)</a>:</h4>
<p>Also this doesn't rule out memory operands forever, just until LLVM gets smarter.</p>



<a name="233438477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438477">(Apr 07 2021 at 06:35)</a>:</h4>
<p>On the other hand there is a certain beauty in just saying "you can't use <code>ebp</code>/<code>ebx</code> as operands, deal with it".</p>



<a name="233438510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438510">(Apr 07 2021 at 06:35)</a>:</h4>
<p>Right up until you need to call a thing that needs those registers.</p>



<a name="233438566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438566">(Apr 07 2021 at 06:36)</a>:</h4>
<p>Then you implement the same hack as musl/glibc yourself. And it's not our problem as compiler devs.</p>



<a name="233438580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438580">(Apr 07 2021 at 06:36)</a>:</h4>
<p>Other than performance, what downsides does this have?</p>



<a name="233438593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438593">(Apr 07 2021 at 06:36)</a>:</h4>
<p>I do acknowledge that we could make this users' problem.</p>



<a name="233438600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438600">(Apr 07 2021 at 06:36)</a>:</h4>
<p>I am somewhat uncomfortable with the amount of complexity this adds to the compiler.</p>



<a name="233438636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438636">(Apr 07 2021 at 06:37)</a>:</h4>
<p>It would be a fixed set of instructions added to the start and end of the asm block.</p>



<a name="233438658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438658">(Apr 07 2021 at 06:37)</a>:</h4>
<p>Also we have to generate the most generic workaround code, which is always going to be less efficient than customized code specific to their use case.</p>



<a name="233438725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438725">(Apr 07 2021 at 06:38)</a>:</h4>
<p>For example musl just uses <code>xchg</code> instructions to swap ebx with a different registers for the 1-4 arguments cases.</p>



<a name="233438891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233438891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233438891">(Apr 07 2021 at 06:40)</a>:</h4>
<p>Sure. We could in theory do that as an optimization if you have few enough register arguments, but rather than put in more cases there, I would sooner encourage people to improve LLVM. Let's minimize complexity but be correct, so that people can write the code they expect to work and have it work.</p>



<a name="233439011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233439011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233439011">(Apr 07 2021 at 06:42)</a>:</h4>
<p>In practice, at least on x86, code that pushes and pops a few registers is not going to be the likely bottleneck in a tight loop; the processor can see that pattern.</p>



<a name="233439066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233439066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233439066">(Apr 07 2021 at 06:43)</a>:</h4>
<p>Let's worry less about the performance, and just make it work the way people expect it to work.</p>



<a name="233439455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233439455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233439455">(Apr 07 2021 at 06:48)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> Do you want to have a go at implementing this?</p>



<a name="233439918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233439918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233439918">(Apr 07 2021 at 06:55)</a>:</h4>
<p>I don't have the bandwidth at the moment. Working on several other things right now. But if we file this as the plan of record, we could invite someone to implement it.</p>



<a name="233439968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233439968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233439968">(Apr 07 2021 at 06:55)</a>:</h4>
<p>I'm still not convinced this is the best way forward...</p>



<a name="233440072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233440072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233440072">(Apr 07 2021 at 06:56)</a>:</h4>
<p>But anyways, at least this doesn't affect ABI-based clobber since LLVM's base/frame registers are always callee-saved.</p>



<a name="233440087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233440087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233440087">(Apr 07 2021 at 06:57)</a>:</h4>
<p>So clobber("ABI") will never clobber them.</p>



<a name="233465466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/233465466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#233465466">(Apr 07 2021 at 10:38)</a>:</h4>
<p>Tbh I don't see why llvm not knowing how to clobber ebx isn't an arbitrary limitation to fix on llvm</p>



<a name="237895619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/237895619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#237895619">(May 07 2021 at 21:54)</a>:</h4>
<p>By accepting backend limitations on arbitrary registers, <code>asm!</code> would only be able to support the intersection of all the inline assembly backends. LLVM uses RBX, next gcc (or whatever) uses R10, and before you know it, no registers are available generally.</p>



<a name="237895690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/237895690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#237895690">(May 07 2021 at 21:54)</a>:</h4>
<p>Given that “The intent is that support for asm! should be independent of the rustc back-end used” (from the RFC), I think this should be transparent to the user. Ideally LLVM would just deal with it, but if not, we need to deal with it in the compiler.</p>



<a name="237895963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/237895963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#237895963">(May 07 2021 at 21:57)</a>:</h4>
<p>If no one has cycles to work on this now, let's at least file an issue documenting what we want the behavior (if we can come to a consensus) to be and track this before stabilization</p>



<a name="237896984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/237896984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#237896984">(May 07 2021 at 22:05)</a>:</h4>
<p>I don't mind filing an issue for it. But I don't know if it is even possible to solve this problem properly.</p>



<a name="237897382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/237897382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#237897382">(May 07 2021 at 22:08)</a>:</h4>
<p>It sounded like Josh proposed an approach that may work? I think it's: use another scratch register if available, or use the stack?</p>



<a name="237897515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/237897515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#237897515">(May 07 2021 at 22:09)</a>:</h4>
<p>Using the stack ends up with very inefficient code and prevents us from ever supporting asm memory operands in the future.</p>



<a name="237897685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/237897685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#237897685">(May 07 2021 at 22:10)</a>:</h4>
<p>well, only if LLVM isn't fixed by then</p>



<a name="237897760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/237897760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#237897760">(May 07 2021 at 22:10)</a>:</h4>
<p>I'm drafting the issue. Should this be about x86(-64) or more general about LLVM-reserved registers for all architectures?</p>



<a name="237898238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/237898238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#237898238">(May 07 2021 at 22:15)</a>:</h4>
<p>I think it's also an issue on ARM: <code>r7</code> holds the syscall number on Linux but is reserved as the frame pointer.</p>



<a name="237898841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Handling%20clobbers/near/237898841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Handling.20clobbers.html#237898841">(May 07 2021 at 22:21)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/85056">https://github.com/rust-lang/rust/issues/85056</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>